package com.mocha.bss.websocket;

import com.coffee.ws.CoffeeWebSocket;
import com.coffee.ws.CoffeeWebSocketBuilder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author: songkui
 * @since: 2023/2/24 9:14
 */
@Component
@Order(1)
@Slf4j
@AllArgsConstructor
public class WsStartInitialize implements ApplicationRunner {

    private final ConnectHandler connectHandler;
    private final UserValidHandler userValidHandler;
    private final CloseHandler closeHandler;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        CoffeeWebSocket.builder(CoffeeWebSocketBuilder.builder()
                        .closeHandler(closeHandler)
                        .connectHandler(connectHandler)
                        .userValidHandler(userValidHandler)
                        .initialize(HandlerMapCmdType.getMap(), "com/scshyzh/bss/ws/handler"))
                .start();

    }

}
